-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Reduce allocations when Activity is enabled #11020
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
- Remove string allocations caused by DiagnosticSource.Stop/StartActivity - Pass the HttpContext directly as the object for StartActivity and StopActivity to avoid the anonymous object allocation. - Though it's a bit ugly, added an HttpContext property to DefaultHttpContext to avoid breaking back-compat (which had to do reflection to get the HttpContext property anyways)
- Mark HttpContext field as editable browsable never - Ran code check
src/Hosting/Hosting/src/Internal/HostingApplicationDiagnostics.cs
Outdated
Show resolved
Hide resolved
Co-Authored-By: Christopher Watford <[email protected]>
cc @lmolkova @SergeyKanzhelev as an FYI, this should be non breaking though. |
@@ -278,7 +279,7 @@ private Activity StartActivity(HttpContext httpContext, out bool hasDiagnosticLi | |||
if (_diagnosticListener.IsEnabled(ActivityStartKey)) | |||
{ | |||
hasDiagnosticListener = true; | |||
_diagnosticListener.StartActivity(activity, new { HttpContext = httpContext }); | |||
StartActivity(activity, httpContext); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this and we may be able to update listener in time for 3.0 to support it. But it is breaking (i.e. there is no HttpContext property on HttpContext type), everyone who attempts to get it will fail.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ooops, you've added property on HttpConetxt 😂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
HttpContext.HttpContext 😄
Contributes to #9594
Before:

After:
